package com.example.paper.common.datam.migrate.processor;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.stereotype.Service;

import java.util.concurrent.*;

@Service
public class DataThreadPool {

    private static final int coreSize = 8;
    private static final int maxSize = 8;

    private static final ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("data-thread-pool-%d").build();

//    CallerRunsPolicy让原来的线程继续处理，只是不走线程池，不至于抛出异常。
    public static final ExecutorService executor = new ThreadPoolExecutor(coreSize, maxSize, 10L, TimeUnit.MINUTES,
        new LinkedBlockingQueue<>(512), namedThreadFactory, new ThreadPoolExecutor.CallerRunsPolicy());
}
